/*
 * User: rant
 * Date: Aug 15, 2007
 *
 *
 */
package laMalinche.testingPlayGround.swingTest;

import laMalinche.testingPlayGround.testModel.PersonVo;
import laMalinche.editableContext.BasicAboutToChangeManager;
import laMalinche.propertyChangeAdapters.model.VOEntityImp;

import java.util.*;

/**
 *
 */
public class SwingFlow {
	final List<PersonVo> flow = new ArrayList<PersonVo>();
	int index;
	private final BasicAboutToChangeManager aboutToChangeManager;

	public BasicAboutToChangeManager getAboutToChangeManager() {
		return aboutToChangeManager;
	}

	public SwingFlow(final PersonVo person) {
		initializeFlow(person);
		aboutToChangeManager = new BasicAboutToChangeManager();
	}

	public  void initializeFlow(PersonVo person) {
		flow.add(person);
		flow.add(person.getFather());
//		flow.add(person);
		flow.add(person.getMother());
	}

	Set<String> getOpenFields() {
		Set<String> set = new HashSet<String>();
		for (int i = index; i < flow.size(); i++) {
			final PersonVo vo = flow.get(i);
			set.add(vo.getOgnl() + ".Age");
		}
		return set;
	}


	public PersonVo getNext() {
        if (flow.size()<=index){
            return null;
        }
        final PersonVo vo = flow.get(index);
		index++;
		final ArrayList<String> list = new ArrayList<String>(getOpenFields());
		aboutToChangeManager.setAboutToChange(list);
		aboutToChangeManager.adviseListeners();
		List<String> set = new ArrayList<String>();
        String ognl = vo.getOgnl();
        String property = ".Age";
        String s = VOEntityImp.getOgnl(vo, "age");
        property =   ognl  + property;
//        set.add(  property.substring(1));
         set.add(  s);
        aboutToChangeManager.setInEditingProcess(set);
		return vo;
	}
}